#! /bin/env python
# coding:utf-8

import urllib
import urllib2
import datetime
import json

ACARD_CLIENT_DEBUG = True

'''
curl http://as.speiyou.com/attend/rest/attendweb/queryGroupByVenue.json -d "classDate=2015-10-22&areaCode=010"
{
    "success":true,
    "message":"success",
    "date":[
        ["ff8080812603129b0126032f428f0016",135],
        ["ff80808145284849014545bb566451a6",145],
        ["ff80808145fd15a80146172facf03dc5",317]]
}
'''

def get_city_class(zipcode, date):
    _data = {}
    _data['areaCode'] = zipcode
    _data['classDate'] = date
    data = urllib.urlencode(_data)
    if ACARD_CLIENT_DEBUG:
        print data

    url = 'http://as.speiyou.com/attend/rest/attendweb/queryGroupByVenue.json'
    rsp_obj = {}
    try:
        req = urllib2.Request(url, data)
        rsp = urllib2.urlopen(req, timeout=5)
        rsp_obj = json.loads(rsp.read())
    except Exception as e:
        print "error:", str(e)

    city_venue_class = rsp_obj.get('date')
    if not city_venue_class:
        return []
    return city_venue_class


if __name__ == '__main__':
    city_class = get_city_class('0512', datetime.date.today().isoformat())
    for attend in city_class:
        print attend
